﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public enum BuffType
{

}

public class Buff
{
	public BuffType buff;
	public float circletime;
	public int level;
	public bool active;
	private float time;

	public void Active(float svtime, int blevel = 1)
	{
		circletime = svtime;
		level = blevel;
		active = true;
	}

	public void Update(float deltatime)
	{
		if(active)
		{
			time -= deltatime;
			
			if (time < 0.0f) 
			{
				// 消耗一层
				Consume(1);

				// 重新设置此层的buff时间
				time = circletime + time;
			}
		}
	}

	public void Consume(int clevel)
	{
		level -= clevel;

		if (level < 0) 
		{
			active = false;
		}
	}
}

public class BuffSystem : MonoBehaviour {
	public List<Buff> buffs;

	// Use this for initialization
	void Start () {
		buffs = new List<Buff> ();
	}
	
	// Update is called once per frame
	void Update () {
		foreach(Buff bf in buffs)
		{
			bf.Update(Time.deltaTime);
		}

		for(int i = buffs.Count - 1; i >= 0; i--)
		{
			if(!buffs[i].active)
			{
				buffs.Remove(buffs[i]);
			}
		}
	}
}
